package com.baidu.health.service.impl;

import com.baidu.health.mapper.TbAskMapper;
import com.baidu.health.pojo.ResultResponse;
import com.baidu.health.pojo.TbAsk;
import com.baidu.health.service.TbAskService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class TbAskServiceImpl extends ServiceImpl<TbAskMapper, TbAsk>
    implements TbAskService{
    @Autowired
    private TbAskMapper tbAskMapper;
    @Override
    public ResultResponse askSelect(TbAsk tbAsk) {
        QueryWrapper queryWrapper=new QueryWrapper();
        if(!StringUtils.isEmpty(tbAsk.getAskTopic())){
            queryWrapper.eq("ask_topic",tbAsk.getAskTopic());
        }
        List<TbAsk> list = tbAskMapper.selectList(queryWrapper);
        return ResultResponse.SUCCESS(list);
    }

    @Override
    public ResultResponse askInsert(TbAsk tbAsk) {
        tbAsk.setCreateTime(new Date());
        tbAskMapper.insert(tbAsk);
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse askUpdate(TbAsk tbAsk) {
        tbAskMapper.updateById(tbAsk);
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse askDeleted(Integer askId) {
        tbAskMapper.deleteById(askId);
        return ResultResponse.SUCCESS();
    }
}




